package com.jdyfy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jdyfy.dto.NoshowCountDTO;
import com.jdyfy.entity.Department;
import com.jdyfy.entity.DepartmentNoshow;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import com.jdyfy.entity.Department;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface DepartmentMapper extends BaseMapper<Department> {

    //根据企业名获取企业信息
    @Select("select * from departments where department_name = #{departmentName}")
    Department getByDepartName(String departmentName);

    //根据企业名集合获取企业信息集合
    List<Department> getDepartsByDepartNames(List<String> departmentNames);

    //获取供应商
    @Select("<script>" +
            "SELECT * FROM departments " +
            "<where>" +
            "<if test='departmentName != null and departmentName != \"\"'> AND department_name LIKE CONCAT('%', #{departmentName}, '%') </if>" +
            "<if test='departmentNumber != null and departmentNumber != \"\"'> AND department_number LIKE CONCAT('%', #{departmentNumber}, '%') </if>" +
            "AND company_role = '供应商'" +
            "</where>" +
            "</script>")
    List<Department> getSuppler(@Param("departmentName") String departmentName,
                                @Param("departmentNumber") String departmentNumber);

    @Insert("insert into department_noshow (department_name,project_name,noshow_reason) VALUES (#{departmentName}, #{projectName}, #{noshowReason})")
    boolean addOrUpdate(DepartmentNoshow departmentNoshow);

    void getNoshowCount();

    List<NoshowCountDTO> getNoshowByDepartment(String departmentName);
}

